var v_list;
$(function(){
	v_list = new Vue({
		el: '#complain-index',
		data: {
			dto:{
				userId:'',
				mobile:'',
				address:''
			},
			deptId:'',
			serId:'',
			theme:'',
			content:'',
			deptList:[],
			serList:[],
		},
		methods: {
			getDeptList: function() {
				this.$http.get('http://192.168.10.45:8888/oc_tengzhou/getDeptList.do', {
				}).then(function(res) {
					//接收后端传来的数据
					console.log(toJson(res.data));
					if(res.data.success){
						this.deptList = res.data.data;
					}
					
				}, function(res) {
					console.log("获取部门出错:"+toJson(res));
				});
			},
			getSerList: function(deptId) {
				this.$http.get('http://192.168.10.45:8888/oc_tengzhou//getSerList.do', {
					deptId:deptId,
					type:'dept'
				}).then(function(res) {
					//接收后端传来的数据
					console.log(toJson(res.data));
					if(res.data.success){
						this.serList = res.data.data;
					}
				}, function(res) {
					console.log("获取事项列表出错:"+toJson(res));
				});
			},
			save: function() {
				if(this.theme==''){
					showRedMsg("message","请填写投诉主题!");
					return false;
				} else if(this.theme.trim()==''){
					showRedMsg("message","请填写投诉主题!");
					return false;
				}
				if(this.content==''){
					showRedMsg("message","请填写投诉内容!");
					return false;
				} else if(this.content.trim()==''){
					showRedMsg("message","请填写投诉内容!");
					return false;
				}
				this.$http.post('http://192.168.10.45:8888/oc_tengzhou/complain/save.do', {
					type:"1",
					userId:this.dto.userId,
					deptId:this.deptId,
					serId:this.serId,
					theme:this.theme,
					content:this.content
				},{
					emulateJSON: true
				}).then(function(res) {
					//接收后端传来的数据
					console.log(toJson(res.data));
					if(res.data.success){
						alert(1);
					}else{
						showRedMsg("message","保存出错");
					}
				}, function(res) {
					showRedMsg("message","保存出错");
					console.log("保存出错:"+toJson(res));
				});
			}
		},
		filters: {
			titlefilter: function(val) {
				if(val != null && val.length > 43)
					val = val.substring(0, 42) + '...';
				return val;
			}
		},
		watch: {
			'deptId': {
				handler: function(val) {
					console.log("进来了"+val+" "+this.deptId);
					this.serId='';
					this.getSerList(this.deptId);
				},
				deep: true
			}},
		ready: function() {
			//初始化获得总页面数和列表数据
			//$("#message-index").load('../s.html');
			$("#left").load('../left.html');
			this.getDeptList();
		}
	});
});		